<?php
// 获取 当前时间 上午 下午 晚上
function getTimePeriod()
{
  // 获取当前小时数
  $hour = date('G');

  // 判断时间段
  if ($hour >= 6 && $hour < 12) {
    return '上午';
  } elseif ($hour >= 12 && $hour < 18) {
    return '下午';
  } else {
    return '晚上';
  }
}

// 输出作者头像URL
function author_head($uid)
{
  global $CACHE;
  if (!$uid) return BLOG_URL . '/admin/views/images/avatar.svg';
  $user_cache = $CACHE->readCache('user');
  if (isset($user_cache[$uid]['photo']['src'])) {
    $head_url = BLOG_URL . $user_cache[$uid]['photo']['src'];
  } else if (isset($user_cache[$uid]['mail'])) {
    $head_url = getGravatar($user_cache[$uid]['mail']);
  } else {
    $head_url = BLOG_URL . '/admin/views/images/avatar.svg';
  }
  return $head_url;
}
// 输出作者名字
function author_name($uid)
{
  global $CACHE;
  if (!$uid) return '';
  $user_cache = $CACHE->readCache('user');
  if (!isset($user_cache[$uid])) return '该用户已注销';
  $author =  $user_cache[$uid]['name'] ? $user_cache[$uid]['name'] : '暂无昵称';
  return $author;
}
// 输出作者信息
function author_des($uid)
{
  global $CACHE;
  if (!$uid) return '';
  $user_cache = $CACHE->readCache('user');
  $des = isset($user_cache[$uid]['des']) ? $user_cache[$uid]['des']  : '该博主没有留下什么话...';
  if ($des) return $des;
}
